package com.suray.system.run.data.mysql.device.battery;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.suray.system.run.core.LowBatteryDescription;
import com.suray.system.run.data.mysql.device.entity.LowBatteryDB;
import com.suray.system.run.data.mysql.device.entity.OffLineDesDB;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class LowBatteryDBServiceImpl extends ServiceImpl<LowBatteryDBMapper, LowBatteryDB> implements LowBatteryDBService {

    @Resource
    LowBatteryDBMapper rgvInfoDBMapper;

    @Override
    public LowBatteryDB findLowBatteryDBBySeries(String series) {
        LambdaQueryWrapper<LowBatteryDB> eq = new QueryWrapper<LowBatteryDB>().lambda()
                .eq(LowBatteryDB::getSeries, series)
                .isNull(LowBatteryDB::getRecoverTime);

        List<LowBatteryDB> lowBatteryDBS = this.list(eq);
        if (lowBatteryDBS.size() == 0) {
            return null;
        }
        return lowBatteryDBS.get(0);
    }

    /**
     * 获取小车所有低电量信息
     * @param startTime
     * @param endTime
     * @return
     */
    public List<LowBatteryDB> getLowBatteryInfoList(String series, Date startTime, Date endTime) {
        QueryWrapper<LowBatteryDB> eq = new QueryWrapper<>();

        eq.lambda().eq(LowBatteryDB::getSeries, series);

        if(startTime != null){
            eq.lambda().ge(LowBatteryDB::getLowTime, startTime);
        }
        if(endTime != null){
            eq.lambda().le(LowBatteryDB::getRecoverTime, endTime);
        }

        return this.list(eq);
    }
}
